define([ "app", "jquery", "md5", "ecb","artDialog","iframeTools", "pagination", "services/UserService","services/TipsService",
		"directives/AudioPlayer",
		"resources/company/CompanyResource",
		"resources/UserResource", "resources/ShareResource" ],
		function(app) {
			var deps = [ "$scope", "$state","$sce", "$timeout", "$window", "$location", "$stateParams","TipsService", "UserService", "UserResource", "ShareResource","CompanyResource" ];

			function controller($scope, $state,$sce,$timeout, $window, $location, $stateParams,TipsService, UserService, UserResource, ShareResource,CompanyResource) {
				
				// 初始化加载数据
				$scope.currentPage = 1;
		        $scope.pages = [];
		        $scope.pageSize = 10;
		        
		        queryData();
				
				// 发布职位
				$scope.releasePosition= function($event){
					$state.go('home.releaseResume');
		        };
		        
		        // 保存职位
				$scope.savePosition= function(){
					var obj ={};
					obj=$scope.positionVo;
					obj.workNature=$("#workNature").val();
					CompanyResource.savePosition(obj).success(function(data){
						$state.go('home.recruitManagement');
		            });
		        };
		        
		        // 更新状态
				$scope.updateStatus= function(id,status){
					CompanyResource.updateStatus(id,status).success(function(data){
						queryData();
		            });
		        };
		        
		        $scope.cancle= function(){
					$state.go('home.recruitManagement');
		        };
				
		        
		        // 修改职位
				$scope.editPosition= function(keyId){
					
					//$state.go('home.editRecruitManagement');
					$state.go('home.editRecruitManagement', {
						keyId:keyId
	                });
		        };
		        
		        
		        function queryData(){
		        	CompanyResource.queryPositionList($scope.currentPage,$scope.pageSize,$scope.keyWord).success(function(data){
						if(data.obj==null){
							return;
						}
		        		$scope.data = data.obj.positionList;
						if(data.obj.count % $scope.pageSize == 0){
		         			$scope.totalPage=Math.floor(data.obj.count/$scope.pageSize);
		        		}else{
		        			$scope.totalPage=Math.floor(data.obj.count/$scope.pageSize)+1;
		        		}
						
						var obj = {
							    wrapid:'wrap1', //页面显示分页器容器id
							    total:data.obj.count,//总条数
							    pagesize:10,//每页显示10条
							    currentPage:1,//当前页
							    onPagechange:onPagechange,
							    //btnCount:7 页数过多时，显示省略号的边界页码按钮数量，可省略，且值是大于5的奇数
							}
							pagination.init(obj);
						
		            });
				}
		        
		        var onPagechange = function(page){
		        	CompanyResource.queryPositionList(page,$scope.pageSize,$scope.keyWord).success(function(data){
						if(data.obj==null){
							return;
						}
		        		$scope.data = data.obj.positionList;
						if(data.obj.count % $scope.pageSize == 0){
		         			$scope.totalPage=Math.floor(data.obj.count/$scope.pageSize);
		        		}else{
		        			$scope.totalPage=Math.floor(data.obj.count/$scope.pageSize)+1;
		        		}
						
						var obj = {
							    wrapid:'wrap1', //页面显示分页器容器id
							    total:data.obj.count,//总条数
							    pagesize:10,//每页显示10条
							    currentPage:page,//当前页
							    onPagechange:onPagechange,
							    //btnCount:7 页数过多时，显示省略号的边界页码按钮数量，可省略，且值是大于5的奇数
							}
							pagination.init(obj);
						
		            });
				}
		        
		        // 发布职位
				$scope.changeColor= function(type){
					
					$("#workNature").val(type);
					if(type==1){
						$("#id1").addClass("position_leida_select");
						$("#id3").removeClass("position_leida_select");
						$("#id2").removeClass("position_leida_select")
						$("#id2").addClass("position_leida");
						$("#id3").addClass("position_leida");
					}
					
					if(type==2){
						$("#id2").addClass("position_leida_select");
						$("#id1").addClass("position_leida");
						$("#id3").addClass("position_leida");
						$("#id3").removeClass("position_leida_select");
						$("#id1").removeClass("position_leida_select")
					}
					
					if(type==3){
						$("#id3").addClass("position_leida_select");
						$("#id1").addClass("position_leida");
						$("#id2").addClass("position_leida");
						$("#id1").removeClass("position_leida_select");
						$("#id2").removeClass("position_leida_select")
					}
		        };
		        
			}
			controller.$inject = deps;
			return app.lazy.controller("RecruitManagementController", controller);
		});
